package com.itcanteen.medical.docker.mq;

import com.alibaba.fastjson.JSONObject;
import com.itcanteen.medical.docker.util.SendSms;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
@Slf4j
public class Consumer {
    @Autowired
    private RedisTemplate redisTemplate;

    @JmsListener(destination = "sms")
    public void sendmsg(String msg)throws Exception{
        log.info("消息队列收到消息:"+msg);

        JSONObject jo = JSONObject.parseObject(msg);

        String mobile=jo.getString("mobile");
        String code=jo.getString("code");
        System.out.println("手机号："+mobile+"验证码："+code);

        redisTemplate.boundHashOps("redisCode").put("code",code);
        redisTemplate.expire("redisCode",1, TimeUnit.MINUTES);

        SendSms.sendMag(mobile,code);
    }
}